<?php
/**
 * Created by PhpStorm.
 * User: wang
 * Date: 2016/7/29
 * Time: 14:58
 */
namespace Home\Controller;

use Think\Controller\RestController;

class IncomeController extends RestController
{
//    function _initialize()
//    {
//        if (!session('user_id')) {
//            $this->ajaxReturn(array(
//                'status' => 'error',
//                'info' => '未登陆'
//            ));
//        }
//    }

    public function income($id)
    {
        $res = M('income')->where('user_id=' . $id)->sum('income');
        if ($res) {
            $this->ajaxReturn(array(
                'sum' => $res,
                'list' => M('income')->where('user_id=' . $id)->select()
            ));
        } else {
            $this->ajaxReturn(array(
                'info' => '暂无收入'
            ));
        }
    }

    public function history($id)
    {
        $res = M('history')->where('user_id=' . $id)->select();
        if ($res) {
            $this->ajaxReturn($res);
        } else {
            $this->ajaxReturn(array(
                'info' => '暂无停车历史'
            ));
        }
    }

    public function ParkHistory($id = 0)
    {
        $res = M('history')->where('parking_id=' . $id)->select();
        if ($res) {
            $info=M('parking')->where('parking_id='.$id)->find();
            $this->ajaxReturn(array(
                'info'=>$info,
                'history'=>$res
            ));
        } else {
            $this->ajaxReturn(array('status' => 'error',
                'info' => '记录不存在'));
        }
    }
}